package com.sjz.image;

import com.sjz.service.ImageService;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

public class NetimageActivity extends Activity {
	   private EditText pathText;
	   private ImageView imageView;
	    
	    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        pathText = (EditText) this.findViewById(R.id.imagepath);
        imageView = (ImageView) this.findViewById(R.id.imageView);
        Button button = (Button) this.findViewById(R.id.button);//得到页面的图片路径 图片展示路径地址
        button.setOnClickListener(new ButtonClickListener());
    }
    
    private final class ButtonClickListener implements View.OnClickListener{

		public void onClick(View v) {
			String path = pathText.getText().toString(); //得到图片的路径
			try{
				byte[] data = ImageService.getImage(path);//得到图片的字节数组
				Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);  
				imageView.setImageBitmap(bitmap);//显示图片
			}catch (Exception e) {
				e.printStackTrace();
				Toast.makeText(getApplicationContext(), R.string.error, 1).show();
			}
		}
    }
}